package com.ilibrary.interceptor;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.ilibrary.constants.MyConstants;
import com.ilibrary.web.vo.AdminVO;
import com.ilibrary.web.vo.UserInfoVO;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class CommonLoginInterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		
		System.out.println("Hello - CommonLoginInterceptor...");
		
		HttpServletRequest request = ServletActionContext.getRequest();
		
		AdminVO adminVO = (AdminVO) request.getSession().getAttribute(MyConstants.ILIBRARY_LOGIN_ADMIN);
		UserInfoVO userInfoVO = (UserInfoVO) request.getSession().getAttribute(MyConstants.ILIBRARY_lOGIN_USER);
		
		if (adminVO == null || userInfoVO == null) {
			return "login";
		}else {
			return actionInvocation.invoke();
		}
	}

}
